package com.grad.why.studentsystem.controller.qlx;

import com.grad.why.studentsystem.controller.ClassesTableController;
import com.grad.why.studentsystem.controller.StudentEvaluateScoreController;
import com.grad.why.studentsystem.domain.User;
import com.grad.why.studentsystem.service.qlxservice.StudentInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

/**
 * @author tyh
 * @Package com.grad.why.studentsystem.controller.qlx
 * @Description:
 * @date 19-5-16 下午1:40
 */
@Controller
@RequestMapping("/studentManageSystem")
public class StudentInfoController {

    @Autowired
    StudentInfoService studentInfoService;

    @Autowired
    StudentEvaluateScoreController studentEvaluateScoreController;

    @Autowired
    ClassesTableController classesTableController;

    @ResponseBody
    @RequestMapping("/getStudentInfo")
    public Object getStudentInfo(HttpSession session){
        User user=(User)session.getAttribute("user");
        int bindId=user.getBindid();
        Map<String,Object> map=new LinkedHashMap<>();
        map.put("data",studentInfoService.getStudentInfo(bindId));
        return map;
    }

    @ResponseBody
    @RequestMapping("/getChooseCourseInfo")
    public Object getChooseCourseInfo(@RequestParam(required = false, defaultValue = "0", value = "offset") int offset,
                                      @RequestParam(required = false, defaultValue = "10", value = "limit") int limit,
                                      @RequestParam(required = false, defaultValue = "", value = "search") String search,
                                      @RequestParam(required = false, value = "order") String order,
                                      HttpSession session){
        try {
            int bindId=((User)session.getAttribute("user")).getBindid();
            List<Map<String,Object>> rows = studentInfoService.getChooseCourseInfo(offset, limit, search,bindId);
            long total = studentInfoService.getChooseCourseInfoLength(search,bindId);
            Map<String, Object> result = new HashMap<>(2);
            result.put("rows", rows);
            result.put("total", total);
            return result;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

    @ResponseBody
    @RequestMapping("/getStudentProfessEstimate")
    public Object getStudentProfessEstimate(HttpSession session){
        User user=(User)session.getAttribute("user");
        int bindId=user.getBindid();
        return studentEvaluateScoreController.test(0,10,"",String.valueOf(bindId),"desc");
    }

    @ResponseBody
    @RequestMapping("/getProfessEstimateRank")
    public Object getProfessEstimateRank(){
        Map<String, Object> result = new HashMap<>(2);
        result=(Map<String, Object>)studentEvaluateScoreController.test(0,10,"","","desc");
        List<Object> list=(List<Object>)result.get("rows");
        for (int i=list.size()-1;i>9;i--){
            list.remove(i);
        }
        Map<String,Object> map=new HashMap<>(2);
        map.put("rows",list);
        result.put("total", 10);
        return map;
    }

    @ResponseBody
    @RequestMapping("/getStudentCourseTable")
    public String getStudentCourseTable(HttpSession session){
        User user=(User)session.getAttribute("user");
        int bindId=user.getBindid();
        return classesTableController.getStudentCourseTableBySid(String.valueOf(bindId));
    }



}
